//
//  BaseTabbarController.m
//  pmmSS
//
//  Created by Mac book on 2017/8/25.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "BaseTabbarController.h"

#import "BaseNavController.h"


#define kClassKey   @"rootVCClassString"
#define kTitleKey   @"title"
#define kImgKey     @"imageName"
#define kSelImgKey  @"selectedImageName"

@interface BaseTabbarController ()

@end

@implementation BaseTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];

    //添加背景图片
    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_bg@2x.png"]];



    NSArray *childItemsArray = @[
                                 @{kClassKey  : @"HomeViewController",
                                   kTitleKey  : @"首页",
                                   kImgKey    : @"icon_tab_home",
                                   kSelImgKey : @"icon_tab_home"
                                   },

                                 @{kClassKey  : @"CategoryViewController",
                                   kTitleKey  : @"分类",
                                   kImgKey    : @"icon_tab_category",
                                   kSelImgKey : @"icon_tab_category"},


                                 @{kClassKey  : @"shoppingCardController",
                                   kTitleKey  : @"购物车",
                                   kImgKey    : @"icon_tab_order",
                                   kSelImgKey : @"icon_tab_order"},

                                 @{kClassKey  : @"MeViewController",
                                   kTitleKey  : @"我的",
                                   kImgKey    : @"icon_tab_me",
                                   kSelImgKey : @"icon_tab_me"}];

    [childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
        UIViewController *vc = [NSClassFromString(dict[kClassKey]) new];

        vc.view.backgroundColor = View_BackgroundColor;
        //vc.title = dict[kTitleKey];
        BaseNavController *nav = [[BaseNavController alloc] initWithRootViewController:vc];

        UITabBarItem *item = nav.tabBarItem;

        item.title = dict[kTitleKey];
        item.image = [UIImage imageNamed:dict[kImgKey]];
        item.selectedImage = [[UIImage imageNamed:dict[kSelImgKey]] imageWithRenderingMode:UIImageRenderingModeAutomatic];
        
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : Global_tintColor} forState:UIControlStateSelected];
        [self addChildViewController:nav];


    }];


}
//禁止屏幕旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

}
-(BOOL)shouldAutorotate{
    return NO;
}
//支持的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}




@end
